

google.load("visualization", "1", {packages:["corechart"]});

google.setOnLoadCallback(loadData);

function loadData() {
	var req = new XMLHttpRequest();
	req.open("GET","/data",true);
	req.onreadystatechange=function() {
		if (req.readyState==4 && req.status==200) {
			var data = JSON.parse(req.responseText);
			drawChart(data);
			console.log(req.responseText);
	    }
	 }
	req.send();	
}
function drawChart(input) {
  var data = google.visualization.arrayToDataTable(input);

  var options = {
    title: 'Company Performance',
    curveType: 'function',
    legend: { position: 'bottom' },
    pointSize: '8'
  };

  var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
	chart.draw(data, options);
}
